/*
 * GeoEquilibrator2.h
 *
 *  Created on: 17 Oct 2011
 *      Author: allan
 */

#ifndef GEOEQUILIBRATOR2_H_
#define GEOEQUILIBRATOR2_H_

// C++ includes
#include <string>
using namespace std;

// GeoReact includes
#include <Core/EquilibriumSolver2.h>
#include <Geochemistry/GeoSystem.h>	
#include <Utils/ConvergenceDiagnostics.h>

// GeoReact forward declarations
class GeoState;

class GeoEquilibrator2
{
public:
	GeoEquilibrator2(const GeoSystem& geosystem);
	
	void ImposeSpeciesMass(const string& species, double mass);
	
	void ImposeSpeciesActivity(const string& species, double activity);
	
	void ImposeElementMass(const string& element, double mass);
	
	void ImposeAcidity(double pH);	
	
	void ImposePartialPressure(const string& gas, double Pg);
	
	void ImposeChargeBalance();
	
	void ResetConditions();
	
	void SetCompositionGuess(const string& species, double mass);
	
	ConvergenceDiagnostics Equilibrate(GeoState& geostate);
	
	ConvergenceDiagnostics Equilibrate(GeoState& geostate, const VectorXd& nGuess);
	
private:
	/// The multiphase instance
	const Multiphase& multiphase;
	
	/// The system of equilibrium-controlled reactions
	const ReactionSystem& eReactions;
	
	/// The equilibrium conditions of the equilibrium problem
	vector<EquilibriumCondition> conditions;
	
	/// The equilibrium solver to solve the equilibrium problem
	EquilibriumSolver2 eSolver;
	
	/// The initial guess for the system composition
	VectorXd n;
};

#endif /* GEOEQUILIBRATOR2_H_ */
